<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript" src="${basePath}/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${basePath}/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="${basePath}/ueditor/lang/zh-cn/zh-cn.js"></script>

<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                imageInfo_1: {
                    validators: {
                        notEmpty: {message: "请上传图片！"},
                        file: {maxSize: 1024 * 1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },
                imageInfo_2: {
                    validators: {
                        notEmpty: {message: "请上传图片！"},
                        file: {maxSize: 1024 * 1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },
                imageInfo_3: {
                    validators: {
                        notEmpty: {message: "请上传图片"},
                        file: {maxSize: 1024 * 1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },
                imageInfo_4: {
                    validators: {
                        notEmpty: {message: "请上传图片"},
                        file: {maxSize: 1024 * 1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },
                shopName: {
                    validators: {
                        notEmpty: {message: "店铺名不可为空"},
                        stringLength: {max: 150,message: "描述最大长度为150"}
                    }
                },
                phone: {
                    validators: {
                        regexp: {
                            regexp:  validateUtil.tel,
                            message: '联系电话格式错误'
                        }
                    }
                },
                postage: {
                    validators: {
                    	notEmpty: {message: "邮费不可为空"},
                        numeric: {
                            message: '邮费只能输入数字'
                        }
                    }
                },
                minAmount: {
                    validators: {
                    	notEmpty: {message: "订单满额包邮不可为空"},
                        numeric: {
                            message: '订单满额包邮只能输入数字'
                        }
                    }
                },
                synopsis: {
                    validators: {
                        stringLength: {max: 2000,message: "描述最大长度为2000"}
                    }
                },
                companyName: {
                    validators: {
                        notEmpty: {message: "企业名称不可为空"},
                        stringLength: {max: 300,message: "企业名称最大长度为300"}
                    }
                },
                postCode: {
                    validators: {
                        notEmpty: {message: "邮政编码不可为空"},
                        regexp: {
                            regexp: validateUtil.zipcode,
                            message: '邮政编码格式错误'
                        }
                    }
                },
                address: {
                    validators: {
                        notEmpty: {message: "详细地址不可为空"},
                        stringLength: {max: 200,message: "详细地址最大长度为200"}
                    }
                }
            }
        });
    }

    /**
     * 编辑入驻店铺信息
     */
	<shiro:hasPermission name="back_gotoEnterShopInfoPage_update">
    function editShopInfo(){
        $("#myModalLabel").empty().text("维护入驻店铺信息");
        /**获取选中行的id**/
        var selectedRow= $("#tt").bootstrapTable('getSelections');
        if(selectedRow.length==1){
            var id=selectedRow[0].shopInfoId;
            $("#btn_edit").attr("data-target","#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/enterShopInfo/getShopInfoObject.sjson",
                data: {shopInfoId:id},
                success: function(result){
                    var data = JSON.parse(result.data);
                    var shop = data.shopInfo;
                    /**隐藏域**/
                    $("#imageUrl_1").val(shop.logoUrl);
                    $("#imageUrl_2").val(shop.bannerUrl);
                    $("#imageUrl_3").val(shop.iDCardsImage);
                    $("#imageUrl_4").val(shop.companyDocuments);
                    $("#shopInfoId").val(shop.shopInfoId);
                    $("#customerId").val(shop.customerId);
                    $("#customerName").val(shop.customerName);
                    $("#businessType").val(shop.businessType);
                    $("#regionLocation").val(data.regionLocation);
                    $("#city").val(data.city);
                    $("#areaCounty").val(data.areaCounty);
                    $("#companyRegistered").val(shop.companyRegistered);
                    $("#legalOwner").val(shop.legalOwner);
                    $("#companyCertification").val(shop.companyCertification);
                    $("#email").val(shop.email);
                    $("#IDCards").val(shop.IDCards);
                    $("#businessLicense").val(shop.businessLicense);
                    $("#taxRegistrationDocuments").val(shop.taxRegistrationDocuments);
                    $("#marketBrand").val(shop.marketBrand);
                    $("#marketBrandUrl").val(shop.marketBrandUrl);
                    $("#isPass").val(shop.isPass);
                    if(shop.passTime!=undefined&&shop.passTime!=""){
                        $("#passTime").val(new Date(shop.passTime).Format("yyyy-MM-dd hh:mm:ss"));
                    }
                    $("#verifier").val(shop.verifier);
                    $("#isClose").val(shop.isClose);
                    $("#isVip").val(shop.isVip);
                    $("#tag").val(shop.tag);
                    $("#description").val(shop.description);
                    if(shop.applyTime!=undefined&&shop.applyTime!=""){
                        $("#applyTime").val(new Date(shop.applyTime).Format("yyyy-MM-dd hh:mm:ss"));
                    }
                    $("#qrCode").val(shop.qrCode);
                    $("#isRecommend").val(shop.isRecommend);
                    $("#shopInfoCheckStatus").val(shop.shopInfoCheckStatus);
                    $("#phoneShowStatus").val(shop.phoneShowStatus);
                    $("#commission").val(shop.commission);
                    $("#passUserName").val(shop.passUserName);
                    /**可见表单控件**/
                    $("#shopName").val(shop.shopName);
                    $("#shopInfoType").val(shop.shopInfoType);
                    $("#shopCategoryId").val(shop.shopCategoryId);
                    $("#templateSet").val(shop.templateSet);
                    $("#mainProduct").val(shop.mainProduct);
                    $("#phone").val(shop.phone);
//                    $("#addressForInvoice").val(shop.addressForInvoice);
                    $("#postage").val(shop.postage);
                    $("#minAmount").val(shop.minAmount);
                    $("#synopsis").val(shop.synopsis);
                    $("#businessHoursStart").val(shop.businessHoursStart);
                    $("#businessHoursEnd").val(shop.businessHoursEnd);
                    $("#companyName").val(shop.companyName);
                    $("#postCode").val(shop.postCode);
                    $("#address").val(shop.address);

                    /**回写预览上传文件所需的信息，如果有上传图片功能添加此代码，否则可以去掉**/
                    initImageForUpdate(1,"sys_shop","image_shopInfo",1,350,350,"${uploadPath}",shop.logoUrl);
                    initImageForUpdate(2,"sys_shop","image_shopInfo",1,4000,4000,"${uploadPath}",shop.bannerUrl);
                    initImageForUpdate(3,"sys_shop","image_shopInfo",1,350,350,"${uploadPath}",shop.iDCardsImage);
                    initImageForUpdate(4,"sys_shop","image_shopInfo",1,350,350,"${uploadPath}",shop.companyDocuments);
                    reValidateForm();
                    removeValidateField('imageInfo_1');
                    removeValidateField('imageInfo_2');
                    removeValidateField('imageInfo_3');
                    removeValidateField('imageInfo_4');
                }
            });
        }else{
            $("#btn_edit").attr("data-target","");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
	</shiro:hasPermission>
</script>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">
				<form id="form1"  method="post" action="${basePath}/back/enterShopInfo/saveOrUpdateShopInfo.sjson">
					<input id="shopInfoId" type="hidden" name="shopInfoId" value=""/>
					<input id="customerId" type="hidden" name="customerId" value=""/>
					<input id="customerName" type="hidden" name="customerName" value=""/>
					<input id="businessType" type="hidden" name="businessType" value=""/>
					<input id="regionLocation" type="hidden" name="regionLocation" value=""/>
					<input id="city" type="hidden" name="city" value=""/>
					<input id="areaCounty" type="hidden" name="areaCounty" value=""/>
					<input id="companyRegistered" type="hidden" name="companyRegistered" value=""/>
					<input id="legalOwner" type="hidden" name="legalOwner" value=""/>
					<input id="companyCertification" type="hidden" name="companyCertification" value=""/>
					<input id="email" type="hidden" name="email" value=""/>
					<input id="IDCards" type="hidden" name="IDCards" value=""/>
					<input id="businessLicense" type="hidden" name="businessLicense" value=""/>
					<input id="taxRegistrationDocuments" type="hidden" name="taxRegistrationDocuments" value=""/>
					<input id="marketBrand" type="hidden" name="marketBrand" value=""/>
					<input id="marketBrandUrl" type="hidden" name="marketBrandUrl" value=""/>
					<input id="isPass" type="hidden" name="isPass" value=""/>
					<input id="passTime" type="hidden" name="passTime" value=""/>
					<input id="verifier" type="hidden" name="verifier" value=""/>
					<input id="isClose" type="hidden" name="isClose" value=""/>
					<input id="isVip" type="hidden" name="isVip" value=""/>
					<input id="tag" type="hidden" name="tag" value=""/>
					<input id="description" type="hidden" name="description" value=""/>
					<input id="applyTime" type="hidden" name="applyTime" value=""/>
					<input id="qrCode" type="hidden" name="qrCode" value=""/>
					<input id="isRecommend" type="hidden" name="isRecommend" value=""/>
					<input id="shopInfoCheckStatus" type="hidden" name="shopInfoCheckStatus" value=""/>
					<input id="phoneShowStatus" type="hidden" name="phoneShowStatus" value=""/>
					<input id="commission" type="hidden" name="commission" value=""/>
					<input id="passUserName" type="hidden" name="passUserName" value=""/>

					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr><td colspan='4' align='center' class="titlebg">店铺信息</td></tr>
						<tr>
							<td class="toright_td"><span style="color:red">* </span>店铺Logo:</td>
							<td class="toleft_td">
								<div class="container">
									<input id="imageUrl_1" type="hidden" name="logoUrl" value=""/>
									<div class="form-group" id="fileWrap1"></div>
								</div>
							</td>
							<td class="toright_td"><span style="color:red">* </span>店铺首页大图:</td>
							<td class="toleft_td">
								<div class="container">
									<input id="imageUrl_2" type="hidden" name="bannerUrl" value=""/>
									<div class="form-group" id="fileWrap2"></div>
								</div>
							</td>
						</tr>

						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span> 店铺名称:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input id="shopName" class="form-control input-sm" type="text" name="shopName" placeholder="请输入店铺名称"/>
								</div>
							</td>
							<td class="toright_td" width="150px"><span style="color:red">* </span>请选择店铺类型:&nbsp;&nbsp;</td>
							<td class="toleft_td">
								<select id="shopInfoType" name="shopInfoType" class="form-control" style="width:250px;">
									<option value="1">平台自营店铺</option>
									<option value="2">平台加盟店铺</option>
								</select>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>店铺分类:</td>
							<td class="toleft_td">
								<select id="shopCategoryId" name="shopCategoryId" class="form-control" style="width:250px;">
									<option value="">--请选择店铺分类--</option>
									<c:forEach items="${shopCategoryList}" var="sc">
										<option value="${sc.shopCategoryId}">${sc.shopCategoryName}</option>
									</c:forEach>
								</select>
							</td>
							<td class="toright_td" width="150px"><span style="color:red">* </span>店铺模板:</td>
							<td class="toleft_td">
								<select id="templateSet" name="templateSet" class="form-control" style="width:250px;">
									<option value="1">--店铺模板(一)--</option>
									<option value="2">--店铺模板(二)--</option>
									<option value="3">--店铺模板(三)--</option>
									<option value="4">--店铺模板(四)--</option>
									<option value="5">--店铺模板(五)--</option>
								</select>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"> 主要销售产品:&nbsp;&nbsp;</td>
							<td  class="toleft_td" >
								<div class="form-group">
									<input id="mainProduct" class="form-control input-sm" type="text" name="mainProduct" placeholder="请输入主要销售产品"/>
								</div>
							</td>
							<td class="toright_td" width="150px"> 联系电话:&nbsp;&nbsp;</td>
							<td  class="toleft_td" >
								<div class="form-group">
									<input id="phone" class="form-control input-sm" type="text" name="phone" placeholder="请输入联系电话"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"> 店铺地址:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input id="address" class="form-control input-sm" type="text" name="address" placeholder="请输入店铺地址"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"> 运费（元）:&nbsp;&nbsp;</td>
							<td  class="toleft_td" >
								<div class="form-group">
									<input id="postage" class="form-control input-sm" type="text" name="postage" placeholder="请输入运费"/>
								</div>
							</td>
							<td class="toright_td" width="150px"> 订单满额包邮（元）:&nbsp;&nbsp;</td>
							<td  class="toleft_td" >
								<div class="form-group">
									<input id="minAmount" class="form-control input-sm" type="text" name="minAmount" placeholder="请输入满额包邮金额"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"> 店铺简介:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input id="synopsis" class="form-control input-sm" type="text" name="synopsis" placeholder="请输入店铺简介"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px">营业开始时间:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group" style="">
									<input id="businessHoursStart" name="businessHoursStart" class="form-control input-sm" type="text"  placeholder="请输入营业开始时间" >
								</div>
							</td>
							<td class="toright_td" width="150px">营业结束时间:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input id="businessHoursEnd" name="businessHoursEnd" class="form-control input-sm" type="text"  placeholder="请输入营业结束时间">
								</div>
							</td>
						</tr>
						<tr><td colspan='4' align='center' class="titlebg">企业信息</td></tr>
						<tr>
							<td class="toright_td"><span style="color:red">* </span>身份证:</td>
							<td class="toleft_td">
								<div class="container">
									<input id="imageUrl_3" type="hidden" name="IDCardsImage" value=""/>
									<div class="form-group" id="fileWrap3"></div>
								</div>
							</td>
							<td class="toright_td"><span style="color:red">* </span>营业执照(三证合一):</td>
							<td class="toleft_td">
								<div class="container">
									<input id="imageUrl_4" type="hidden" name="companyDocuments" value=""/>
									<div class="form-group" id="fileWrap4"></div>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"> 企业名称:&nbsp;&nbsp;</td>
							<td  class="toleft_td" >
								<div class="form-group">
									<input id="companyName" class="form-control input-sm" type="text" name="companyName" placeholder="请输入企业名称"/>
								</div>
							</td>
							<td class="toright_td" width="150px"> 邮政编码:&nbsp;&nbsp;</td>
							<td  class="toleft_td" >
								<div class="form-group">
									<input id="postCode" class="form-control input-sm" type="text" name="postCode" placeholder="请输入邮政编码"/>
								</div>
							</td>
						</tr>
						<%--<tr>
							<td class="toright_td" width="150px"> 详细地址:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input id="address" class="form-control input-sm" type="text" name="address" placeholder="请输入详细地址"/>
								</div>
							</td>
						</tr>--%>

					</table>

				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>

		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>